<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%
	String path = request.getContextPath();
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>融资机构优先级</title>
<jsp:include page="../../import.jsp" flush="true" />
<style type="text/css">
	.img {
		width:40px; 
		height: 20px;
		cursor: pointer;
	}
	.img1 {
		width:40px; 
		height: 20px;
		cursor: default;
	}
</style>
</head>

<body class="iframeBody">
	<div class="Wrapper">
		<div>
			<form id="ligerForm">
				<div class="fieldset1 tabel_col clearFix">
	
			<div class="fieldBox col_100">
						<div style="width: 100%; ">
		<table style="BORDER-COLLAPSE: collapse;margin-bottom:20px" borderColor=#ECECEC height=40 cellPadding=1 width="100%" align=center border=1> 
							
				<thead>
								<tr style="background:#E7FEF4;">
									<th class="tbLabel" rowspan="2"></th>
									<th class="tbLabel" style="text-align: center;" rowspan="2">机构名称</th>
									<th class="tbLabel" style="text-align: center;" rowspan="2">是否服务</th>
									<th class="tbLabel" style="text-align: center;" rowspan="2">业务线</th>
									<th class="tbLabel" style="text-align: center;" rowspan="2">总授信额度（元）</th>
									<th class="tbLabel" style="text-align: center;" rowspan="2">剩余授信额度（元）</th>
									<th class="tbLabel" style="text-align: center;display:none;" rowspan="2">优先级值</th>
									<th class="tbLabel" style="text-align: center;" rowspan="2">优先级</th>
									<th class="tbLabel" style="text-align: center;" colspan="6">机构限额信息</th>
								</tr>
								<tr style="background:#E7FEF4">
									<th class="tbLabel" style="text-align: center;">项目类型</th>
									<th class="tbLabel" style="text-align: center;">融资额上限（万）</th>
									<th class="tbLabel" style="text-align: center;">设备数上限（台）</th>
									<th class="tbLabel" style="text-align: center;">主车数量上限</th>
									<th class="tbLabel" style="text-align: center;">挂车数量上限</th>
									<th class="tbLabel" style="text-align: center;">是否支持纯挂</th>
								</tr>
							</thead>
							<tbody>
								<c:forEach items="${insList}" var="item" varStatus="status">
								<tr> 
									<td rowspan="${item.rowspan}" style="text-align: center; height:10px;">${status.index+1}</td>
									<td rowspan="${item.rowspan}" style="text-align: center; height:10px;<c:if test="${item.isService == '1'}">color: red;</c:if>">${item.fundRasInsNm}</td>
									<td rowspan="${item.rowspan}" style="text-align: center; height:10px;">
									
									<select  id="isService${status.index}" onchange="changeNum(${status.index},'${item.id}','${item.zgNum}')" name="isService" id="zgFlag" data-value=""  >
					                    <option value="1" <c:if test="${item.isService == '1'}">selected</c:if>>是</option>
					                    <option value="0"  <c:if test="${item.isService == '0'}">selected</c:if>>否</option>
					                </select>
									</td>
									<td rowspan="${item.rowspan}" style="text-align: center; height:10px;">
										${item.bussinessLineNm}
									</td>
									<td rowspan="${item.rowspan}" style="text-align: center; height:10px;">${item.crLmt}</td>
									<td rowspan="${item.rowspan}" style="text-align: center; height:10px;">${item.crBal}</td>
									<td rowspan="${item.rowspan}" style="text-align: center; height:10px;display:none; ">
									<input id="zgNum${status.index}" sid="${item.id}" <c:if test="${item.isService == '0'}">disabled</c:if>
									 name="zgNum" value='${item.zgNum}'  type="text" style="width:30px;"   class="ui-textbox"  >
									</td>
									<td rowspan="${item.rowspan}" style="text-align: center; height:10px;">
										
										<c:if test="${item.isService == '1'}"><!-- 服务中的机构 -->
											<c:if test="${status.first}"><!-- 第一个机构，不可点击向上 -->
												<img class="img1" src='<%=path%>/resource/lib/images/u147.png'/>
											</c:if>
											<c:if test="${!status.first}"><!-- 非第一个机构，可点击向上 -->
												<img class="img"  onclick='change("${item.id}","${insList[status.index-1].id}","up")'  src='<%=path%>/resource/lib/images/u143.png'/>
											</c:if>
											
											<c:if test="${insList[status.index+1].isService == '0'}"><!-- 当前节点的下一个机构-->
												<img class="img1" src='<%=path%>/resource/lib/images/u161.png'/>
											</c:if>
											<c:if test="${insList[status.index+1].isService == '1'}">
												<img class="img"  onclick='change("${item.id}","${insList[status.index+1].id}","down")'  src='<%=path%>/resource/lib/images/u145.png'/>
											</c:if>
										</c:if>
										
										<c:if test="${item.isService == '0'}"><!-- 不服务的机构 -->
											<img class="img1" src='<%=path%>/resource/lib/images/u147.png'/>
											<img class="img1" src='<%=path%>/resource/lib/images/u161.png'/>
										</c:if>
										
									</td>
									<td style="text-align: center;">${item.prjTyp}</td>
									<td style="text-align: center;">${item.insLimAmt}</td>
									<td style="text-align: center;">${item.insLimMum}</td>
									<td style="text-align: center;">${item.mainLimNum}</td>
									<td style="text-align: center;">${item.handLimNum}</td>
									<td style="text-align: center;">${item.isHang}</td>
								</tr>
								
									<c:forEach items="${item.fundRasInsLimList}" var="fundRasInsLim" begin="1">
									<tr>
										<td style="text-align: center;">${fundRasInsLim.PRJ_TYP}</td>
										<td style="text-align: center;">${fundRasInsLim.INS_LIM_AMT_}</td>
										<td style="text-align: center;">${fundRasInsLim.INS_LIM_NUM_}</td>
										<td style="text-align: center;">${fundRasInsLim.INS_MAIN_LIM_NUM_}</td>
										<td style="text-align: center;">${fundRasInsLim.INS_HAND_LIM_NUM_}</td>
										<td style="text-align: center;">${fundRasInsLim.INS_IS_HANG}</td>
									</tr>
									</c:forEach>
								</c:forEach>
							
		</table>
		</div>
		</div>
		</div>
		<!-- <div class="clearFix" style="text-align:center">

			<span id="cr_bsc_info_add_btn_id" class="sq-button sq-button-round" onclick="save();">保存 </span>
		</div> -->
	</form>
	</div>
	</div>
	<script type="text/javascript">
	
		//点击上下箭头图片，调整机构优先级
		function change(id,relId,operate){
			
			var wait_dialog = null;
			$.ajax({
				type: 'post',
				dataType: 'json',
				data: {'id':id,'relId':relId},
				url: '<%=path%>/rfbase/fribaseinfo/modifyPriority.do',
				beforeSend : function() {
					wait_dialog = $.ligerDialog.SQalert({
						content : LogUtils.LOG_CMM_DATA_LOADING,
						SQ_type : "waitting"
					});
				},
				success : function(msg) {
					//console.log("success : function(msg):");
					//console.log(msg);
					if (msg.success == 1) {
						location.reload();
					} else {
						wait_dialog.close();
						$.ligerDialog.SQalert({
							content : msg.info,
							SQ_type : "error"
						});
					}
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					wait_dialog.close();
					$.ligerDialog.SQalert({
						content : "网络错误，请稍后重试",
						SQ_type : "error"
					});
				}
			});
		}
	
			
		function changeNum(index,id,zgNum){
			
			if($("#isService"+index).val()=='1' ){
				$("#isService"+index).val(1);
			}else{
				$("#isService"+index).val(0);
			}
			
			var wait_dialog = null;
			$.ajax({
				type: 'post',
				dataType: 'json',
				async:false,
				data: {'id':id,'isService':$("#isService"+index).val()},
				url: '<%=path%>/rfbase/fribaseinfo/modifyIsService.do',
				beforeSend : function() {
					wait_dialog = $.ligerDialog.SQalert({
						content : LogUtils.LOG_CMM_DATA_LOADING,
						SQ_type : "waitting"
					});
				},
				success : function(msg) {
					if (msg.success == 1) {
						location.reload(true);
					} else {
						wait_dialog.close();
						$.ligerDialog.SQalert({
							content : msg.info,
							SQ_type : "error"
						});
					}
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					wait_dialog.close();
					$.ligerDialog.SQalert({
						content : "网络错误，请稍后重试",
						SQ_type : "error"
					});
				}
			});
		}
		
		
		
		//保存
		function save(){
			//校验优先级不能重复
			for(var i=0;i<${insSize};i++){
				if($("#isService"+i).val()=='1' ){
						if($("#zgNum"+i).val()==''){
							alert("请填写优先级!");
							$("#zgNum"+i).focus();
							return;
						}
						var re=/^\d*\.{0,1}\d*$/;
						if(re.exec($("#zgNum"+i).val())==null){
							alert("请输入数字格式!");
							$("#zgNum"+i).focus();
							return;
						}
				}
				for(var j=i+1;j<${insSize};j++){
						if($("#isService"+j).val()=='1' && $("#zgNum"+j).val()==$("#zgNum"+i).val()){
							alert("优先级不可重复，请核查");
							$("#zgNum"+j).val("");
							$("#zgNum"+j).focus();
							return;
						}
				}
			}
			var ids="";
			var isServices="";
			var zgNums="";
			for(var i=0;i<${insSize};i++){
				ids=ids+$("#zgNum"+i).attr("sid")+",";
				zgNums=zgNums+$("#zgNum"+i).val()+",";
				isServices=isServices+$("#isService"+i).val()+",";
			}
            var data = {
            		ids:ids,
            		zgNums:zgNums,
            		isServices:isServices	
            };
           var url="<%=path%>/rfbase/fribaseinfo/modifyNums.do";
           
			AjaxUtils.ajaxPost(url, data, addCallback);
		}

		//新增回调
		function addCallback(msg) {
			if (msg.success == 1) {
				UIUtils.alertSuccess(msg.info);
				location.reload(true);
				
			} else {
				UIUtils.alertError(msg.info);
			}
		}
		
		

	</script>

</body>
</html>
